<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
      <el-form label-position="right" :model="candidateForm" :label-width="formLabelWidth" disabled="disabled">
        <el-row>
          <el-col :span="11">
            <el-form-item label="用户名">
              <el-input v-model="candidateForm.username"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="姓名">
              <el-input v-model="candidateForm.name"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="密码">
              <el-input v-model="candidateForm.password"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="性别">
              <el-select v-model="candidateForm.gender" placeholder="请选择性别">
                <el-option label="男" :value="1"></el-option>
                <el-option label="女" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="出生日期">
              <el-input v-model="candidateForm.birthDate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="联系电话">
              <el-input v-model="candidateForm.contactPhone"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="邮箱">
              <el-input v-model="candidateForm.email"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="省/市/区">
              <el-cascader
                  v-model="provinceCityArea"
                  :options="provinceCityAreaOptions"
                  :props="{ expandTrigger: 'hover', value: 'code', label: 'name' }"></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="家庭地址">
              <el-input v-model="candidateForm.address"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="创建时间">
              <el-input v-model="candidateForm.createTime"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="最后修改时间">
              <el-input v-model="candidateForm.modifyTime"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import candidateApi from '@/api/candidateApi'
import areas from "@/locales/area.json";
export default {
  name: 'CandidateView',
  props: ['id'],
  mixins: [
  ],
  data () {
    return {
      candidateForm: {
      },
      provinceCityArea: [],
      provinceCityAreaOptions: areas.provinces
    }
  },
  created () {
    if (this.id) {
      candidateApi.findById(this.id)
          .then(resp => {
            if (resp && resp.code === 1) {
              this.candidateForm = resp.data
              this.provinceCityArea = []
              if (this.candidateForm.province) {
                this.provinceCityArea.push(this.candidateForm.province)
              }
              if (this.candidateForm.city) {
                this.provinceCityArea.push(this.candidateForm.city)
              }
              if (this.candidateForm.area) {
                this.provinceCityArea.push(this.candidateForm.area)
              }
            } else {
              this.$message.error('获取数据失败')
            }
          })
          .catch(error => {
            console.error('获取数据失败:', error)
          })
    }
  },
  methods: {
    onBack () {
      this.$emit('close-candidate-view-event')
    }
  }
}
</script>

<style lang="scss">
</style>